package com.sdy.usercenter.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdy.usercenter.biz.model.SysUserApp;
import com.sdy.usercenter.biz.mapper.SysUserAppMapper;
import com.sdy.usercenter.biz.service.SysUserAppService;
import com.sdy.mvc.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzq
 * @since 2019-07-10
 */
@Slf4j
@Service
public class SysUserAppServiceImpl extends BaseServiceImpl<SysUserApp> implements SysUserAppService {
    @Autowired
    private SysUserAppMapper sysUserAppMapper;

    @Override
    public void addUsers(List<Integer> userIdList, Integer appId) {
        Date now = new Date();
        for (Integer userId : userIdList) {
            SysUserApp sysUserApp = new SysUserApp()
                    .setAppResId(appId)
                    .setUserId(userId)
                    .setCreateTime(now);
            save(sysUserApp);
        }
    }

    @Override
    public void removeUsers(List<Integer> userIdList, Integer appId) {
        if (userIdList.isEmpty()) {
            return;
        }
        remove(new LambdaQueryWrapper<SysUserApp>()
                .eq(SysUserApp::getAppResId, appId)
                .in(SysUserApp::getUserId, userIdList)
        );
    }
}
